package cn.com.my.dh;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class TestHB {
	
	
	public class ProdInfo {
		private String barCode;
		private String quantity;
		
		public ProdInfo() {
		}
		
		public ProdInfo(String barCode, String quantity) {
			this.barCode = barCode;
			this.quantity = quantity;
		}

		public String getBarCode() {
			return barCode;
		}
		public void setBarCode(String barCode) {
			this.barCode = barCode;
		}
		public String getQuantity() {
			return quantity;
		}
		public void setQuantity(String quantity) {
			this.quantity = quantity;
		}
	}
	
	
	private static Map<String, Integer> getNameCount(Map<Integer, ProdInfo> map) {  
        Map<String, Integer> resultMap = null;  
        if ((map != null) && !map.isEmpty()) {  
            resultMap = new HashMap<String, Integer>();  
            for (Integer key : map.keySet()) {  
            	ProdInfo p = map.get(key);  
                Integer count = resultMap.get(p.getBarCode());  
                if (count != null) {  
                    resultMap.put(p.getBarCode(), count + Integer.valueOf(p.getQuantity()));  
                } else {  
                    resultMap.put(p.getBarCode(), Integer.valueOf(p.getQuantity()));  
                }  
            }  
        }  
        return resultMap;  
    } 
	
	
	public static void main(String[] args) {  
		TestHB t = new TestHB();  
        Map<Integer, ProdInfo> map = new HashMap<Integer, ProdInfo>();  
        map.put(1, t.new ProdInfo("zhansan", "2"));  
        map.put(2, t.new ProdInfo("zhansan", "3"));  
        map.put(3, t.new ProdInfo("lisi", "5"));  
        map.put(4, t.new ProdInfo("lisi", "6"));  
        
//        System.out.println(getNameCount(map));  
        
        List<ProdInfo> prodInfoList = new ArrayList<ProdInfo>();
        Map<String, Integer> ml = getNameCount(map);//将barcode相同的prod合并数量相加
		for (String key : ml.keySet()) {  
			Integer quantity = ml.get(key);  
			ProdInfo prodInfo = t.new ProdInfo(key, quantity.toString());
			prodInfoList.add(prodInfo);
        } 
		
		
		System.out.println(prodInfoList);
		
		System.out.println(getNext("ASMDH"));
		
		String str = "1234567890abcde";
		String sub = str.substring(str.length()-5, str.length());
		System.out.println(sub);
		
		
		
    } 
	
	static String getNext(String prefix){
		DateFormat format1 = new SimpleDateFormat("yyMMddHHmm");  
        
		String nextNo = null ;
		Date date = new Date();
		String today  = format1.format(date);
		String orderFormat = prefix + today  + "%05d";
		nextNo  = String.format(orderFormat, 100023);
		
		return nextNo;
	}
}
